package com.zzptc.zzsgz.bdsjws.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.zzptc.zzsgz.bdsjws.MyApplication;
import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.vo.BBX;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/5/24 024 .
 */

public class BBXAdapter extends RecyclerView.Adapter<BBXAdapter.MyViewHolder> {
    List<BBX> list;
    public BBXAdapter(List<BBX> list){
        this.list=list;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.bbx_item,parent,false);
        MyViewHolder myViewHolder=new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
      BBX bbx=  list.get(position);
        //讲从数据库中取得的pic图片的 String---->Drawable
        Context context=MyApplication.getContext();
        int pic_int= context.getResources().getIdentifier(bbx.getIcon(),"mipmap",MyApplication.getContext().getPackageName());
        Drawable drawable=context.getResources().getDrawable(pic_int);
        holder.iv_bbxpic.setImageDrawable(drawable);
        holder.tv_bbxname.setText(bbx.getName());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
//每个项
    public class MyViewHolder extends RecyclerView.ViewHolder{
    @BindView(R.id.iv_bbxpic)
    ImageView iv_bbxpic;
    @BindView(R.id.tv_bbxname)
    TextView tv_bbxname;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
